#include "send_recv.h"
#include "unistd.h"

// #define CONF_LOOP_WR 1024
// #define CONF_LOOP_WR 512, which gets from Makefile;
// #define CONF_LOOP_RD CONF_LOOP_WR*50

// #define MULTI_CORE 1

int main(int argc, char *argv[])
{
	int opt;
	int i;
	while(1){
		system("clear");
		printf("//======================================================//\n");
		printf("\tPlease chose your option:\n");
		printf("\t0:\tset sel to 0, i.e., running mode\n");
		printf("\t1:\tset sel to 1, i.e., configuring mode\n");
		printf("\t2:\tread sel\n");
		printf("\t3:\tconfigure instruction\n");
		printf("\t4:\tread instruction\n");
		printf("\t5:\topen/close black pressure\n");
		printf("\t6:\tset sel to f, i.e., configuring mode\n");
		printf("\tNote:\tcurrent RAM size is %d KB\n",CONF_LOOP_WR/4);
		printf("//======================================================//\n");
		printf("opt is: ");
		scanf("%d", &opt);

		if(opt == 0){
			#ifdef MULTI_CORE
				int bitmap;
				printf("status of pe in bitmap is: (0 is running) ");
				scanf("%d", &bitmap);

				set_read_sel(0, bitmap);
			#else
				set_read_sel(0, 0);
			#endif
		}
		else if(opt == 1){
			#ifdef MULTI_CORE
				int bitmap;
				printf("status of pe in bitmap is: (0 is running)");
				scanf("%d", &bitmap);

				set_read_sel(0, bitmap);
			#else
				set_read_sel(0, 1);
			#endif
		}
		else if(opt == 2)
			set_read_sel(1, 0);
		else if(opt == 3){
			char fileName[30] = "firmware.hex";
			int lineNum = 0;
			for (i = 0; i < CONF_LOOP_WR; i++){
				lineNum = 64*i;
				write_tcm(fileName, lineNum);
			}
		}
		else if(opt == 4){
			for (i = 0; i < (CONF_LOOP_WR*50); i++){
				read_tcm(i);
			}
		}
		else if(opt == 5){
			system("clear");
			printf("//======================================================//\n");
			printf("\tPlease chose your option:\n");
			printf("\t0:\tclose black pressure\n");
			printf("\t1:\topen black pressure\n");
			printf("//======================================================//\n");
			printf("opt is: ");
			int value;
			scanf("%d", &value);
			open_backPressure(value);
		}
		else if(opt == 6){
			set_read_sel(0, 15);
		}
	}

    return 0;
} 
